package com.course.cdspringboot.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.mapping.StatementType;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper{

    // 学生获取自己的基本信息
    @Select("SELECT * FROM view_students where  uid=#{uid}")
    Map<String, Object> getStudentHomeInfo(Long uid);

    // 老师获取自己的学生列表
    @Select("SELECT * FROM view_students where  teacher_id=#{teacherId}")
    List<Map<String, Object>> getMyStudents(Long teacherId);

    // 获取所有学生的信息
    @Select("SELECT * FROM view_students")
    List<Map<String, Object>> getAllStudents();

    // 学生更新自己的信息
    @Update("UPDATE students SET phone=#{phone}, email=#{email}, address=#{address} WHERE uid=#{uid}")
    int updatePersonalInfo(Map<String, Object> studentDetailInfo);

    // 添加学生
    @Select("{call add_student(#{p_username}, #{p_password}, #{p_name}, #{p_gender}, #{p_birthdate}, #{p_teacher_id}, #{p_student_stage_id}, #{p_major_id}, #{p_enrollment_date}, #{p_phone}, #{p_email}, #{p_address}, #{error_code,mode=OUT,jdbcType=INTEGER}, #{error_msg,mode=OUT,jdbcType=VARCHAR})}")
    @Options(statementType = StatementType.CALLABLE)
    void addStudent(Map<String, Object> studentInfo);

}
